package ziv.map.activity;

import java.io.IOException;

import ziv.map.mapMain;
import ziv.map.R;
import ziv.map.utils.ConfigControl;
import ziv.map.utils.Constant;
import ziv.utils.html.HttpDownloader;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Config extends Activity {
	EditText configEditText = null;
	Button configButton = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.config);
		configButton = (Button) findViewById(R.id.configButton);
		configEditText = (EditText) findViewById(R.id.configEditText);
		try {
			String mobile=ConfigControl.getSelfMobile();
			
			//Log.v("ziv","***"+String.valueOf(getIntent().getBooleanExtra("config", false))+"****");
			//1、如果本机手机号已经设置完则直接跳转到主页面 ； 2 、如果是特意点击设置，则还停留在这个页面
			if(!"".equals(mobile) && !getIntent().getBooleanExtra("config", false)){ 
				Intent intent = new Intent(Config.this, mapMain.class);
				startActivity(intent);
				finish();
			}
			configEditText.setText(mobile);
			Constant.selfMobile=mobile;			// 改全局变量
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 提取配置文件

		// 鼠标点击事件
		configButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				
				if (null==configEditText.getText() || "".equals(configEditText.getText().toString())) {
					Toast.makeText(getApplicationContext(), "文本框空", Toast.LENGTH_LONG);
					
				} else {
					ConfigControl.setSelfMobile(configEditText.getText().toString());	// 存储到手机文件
					
					
					HttpDownloader httpDownloader=new HttpDownloader();
					String addMember=Constant.addMember;
					addMember=addMember.replace("{1}", configEditText.getText().toString());
					String response=httpDownloader.download(addMember);// 添加到网络数据库
					
					
					Constant.selfMobile=configEditText.getText().toString();			// 改全局变量
					Intent intent = new Intent(Config.this, mapMain.class);
					startActivity(intent);
					
				}
				finish();
			}

		});
		
		// editiontextView.setText(Html.fromHtml("<h1>亲人位置</h1>"));
	}

}
